package com.zone.vehicle.superapp.utils;

import android.app.Application;
import android.content.Context;

import com.zone.sdk.module.account.entity.UserInfoEntity;
import com.zone.sdk_api.common.Content;

import org.apache.commons.lang3.ObjectUtils;

/**
 * @Author: pkqlqx
 * @CreateDate: 2022/3/14 16:36
 * @Description:
 */
public class LoginUtil {

    private static LoginUtil loginUtil;

    private static Application application;

    public static LoginUtil getInstance(){
        if (loginUtil == null){
            loginUtil = new LoginUtil();
        }
        return loginUtil;
    }

    public void init(Application application){
        LoginUtil.application = application;
    }

    private LoginUtil(){
    }

    public static boolean isLogin(){
        return ObjectUtils.isNotEmpty(SharedPreferencesUtil.getInstance(application).getObject(Content.USER_INFO, UserInfoEntity.class));
    }

    public static UserInfoEntity getUserInfo(){
        if (isLogin()){
            return (UserInfoEntity)SharedPreferencesUtil.getInstance(application).getObject(Content.USER_INFO, UserInfoEntity.class);
        }
        return null;
    }

    public static String getUserId(){
        if (isLogin()){
            UserInfoEntity userInfoEntity = (UserInfoEntity)SharedPreferencesUtil.getInstance(application).getObject(Content.USER_INFO, UserInfoEntity.class);
            return String.valueOf(userInfoEntity.getId());
        }
        return "";
    }

}
